#include("../../comm/ListHead.html")
<style>
    .menufirst{ color:darkolivegreen; font-weight:600 }
    .menusecond{ color:#B45309 }
    .menuthird{ color:#666666 }
    .menudesc{ color:red }
</style>
<div class="layui-fluid layui-anim layui-anim-scale">
    <div class="layui-row layui-col-space5">
        <div class="layui-col-md2 ">
            <div class="layui-card height-auto">
                <div style="padding:4px 5px;">
                    <button class="layui-btn layui-btn-warm layui-btn-xs" style="margin:0px" lay-event="LoadRootMenu">系统根菜单</button>
                    <button class="layui-btn btn-change-8 layui-btn-xs" style="margin:0px" lay-event="LoadTree">
                        <i class="layui-icon">&#xe669;</i>刷新树
                    </button>
                </div>
                <div id="tree_1" class="demo-tree demo-tree-box height-scoll1"></div>
            </div>
        </div>
        <div class="layui-col-md10 ">
            <div class="layui-card height-auto">
                <div class="card-search SearchTable">
                    <p style="float:right">
                        <input type="hidden" id="pmenu_id" name="pmenu_id" value="#(form.data.menuid??)"/>
                        <label class="table-search-title">路经</label>
                        <input type="text" id="menupath" class="table-search-text width200">
                        <button class="layui-btn layui-btn-warm layui-btn-sm" lay-event="DoSearch">
                            搜索
                        </button>
                    </p>
                    <i class="layui-icon layui-icon-slider"></i>
                    <span id="titles" class="color_green">根菜单 / #(form.data.title) / <span class="text-pink-400">三级菜单</span></span>
                </div>
                <div class="layui-card-body">
                    <table class="layui-hide" id="table_1" lay-filter="table_1"></table>

                    <script type="text/html" id="bar_title_grade1">
                        <div class="layui-btn-container">
                            <button class="layui-btn layui-btn-sm btn-add" lay-event="AddSysMenuFirst">
                                <i class="layui-icon">&#xe608;</i> 添加一级菜单
                            </button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-edit" lay-event="EditSysMenuFirst">修改</button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-del" lay-event="DelSysMenu">删除</button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-change-13" lay-event="SetMenuRole">配置角色</button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-change-14" lay-event="SetMenuUser">配置人员</button>
                        </div>
                    </script>

                    <script type="text/html" id="bar_title_grade2">
                        <div class="layui-btn-container">
                            <button class="layui-btn layui-btn-sm btn-add" lay-event="AddSysMenuSecond">
                                <i class="layui-icon">&#xe608;</i> 添加二级菜单
                            </button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-edit" lay-event="EditSysMenuSecond">修改</button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-del" lay-event="DelSysMenu">删除</button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-change-13" lay-event="SetMenuRole">配置角色</button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-change-14" lay-event="SetMenuUser">配置人员</button>
                        </div>
                    </script>

                    <script type="text/html" id="bar_title_grade3">
                        <div class="layui-btn-container">
                            <button class="layui-btn layui-btn-sm btn-add" lay-event="AddSysMenuThird">
                                <i class="layui-icon">&#xe608;</i> 添加三级菜单
                            </button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-edit" lay-event="EditSysMenuThird">修改</button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-del" lay-event="DelSysMenu">删除</button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-change-13" lay-event="SetMenuRole">配置角色</button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-change-14" lay-event="SetMenuUser">配置人员</button>
                        </div>
                    </script>

                    <script type="text/html" id="bar_title_grade4">
                        <div class="layui-btn-container">
                            <button class="layui-btn layui-btn-sm btn-add" lay-event="DrSysActivityList">
                                <i class="layui-icon">&#xe608;</i> 导入功能
                            </button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-edit" lay-event="EditSysActivity">修改</button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-del" lay-event="DelSysMenuActivity">删除</button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-change-13" lay-event="SetActivityRole">配置角色</button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-change-14" lay-event="SetActivityUser">配置人员</button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-change-17" lay-event="ScyActivityPath">同步地址</button>
                        </div>
                    </script>
                    <script type="text/html" id="temp_is_log">
                        <input type="checkbox" lay-skin="primary" field="is_log" msg="设置记录日志" value="{{d.act_id}}" lay-filter="ChangeActivityTag" {{ d.is_log ? 'checked' : '' }}>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<script language="JavaScript">

    layui.use(['myTable', 'table', 'form', 'myTree', 'myTool'], function () {
        admin = layui.admin, table = layui.table, form = layui.form,
                myTree = layui.myTree, myTool = layui.myTool, myTable = layui.myTable;
        var $ = layui.$;
        var tableindex, tableindex2;
        pmenu_id = $("#pmenu_id").val(), grade = 2, title = '';
        treedata = #(form.data.tree);

        //树渲染
        treeindex = myTree.render({
            url: 'LoadTreeDataApi'
            , init: $("#pmenu_id").val()
            , data: treedata, onlyIconControl: false
            , click: function (obj) {
                var loadindex = layer.load();

                var data = obj.data;
                if (data.turn) {
                    grade = data.datas.grade;
                    pmenu_id = data.datas.menuid;
                    title = data.datas.title;
                    $("#pmenu_id").val(pmenu_id);
                    if (grade == 1) {
                        tableindex = TableMenu();
                        table.hideCol("table_1", [{field: 'menu_icon', hide: true}])
                        $("#titles").html("根菜单 / " + data.datas.titles + " / <span class=\"menudesc\">二级子菜单</span>");
                        tableindex.reload({toolbar: '#bar_title_grade2', where: {pmenu_id: pmenu_id, grade: grade}});
                    } else if (grade == 2) {
                        tableindex = TableMenu();
                        table.hideCol("table_1", [{field: 'menu_icon', hide: true}])
                        $("#titles").html("根菜单 / " + data.datas.titles + " / <span class=\"menudesc\">三级菜单</span>");
                        tableindex.reload({toolbar: '#bar_title_grade3', where: {pmenu_id: pmenu_id, grade: grade}});
                    } else {
                        $("#table_1").hide();
                        $("#titles").html("根菜单 / " + data.datas.titles + " / <span class=\"menudesc\">功能列表</span>");
                        tableindex = TableActivity();
                        tableindex.reload({toolbar: '#bar_title_grade4', where: {menu_id: pmenu_id}});
                    }
                    layer.close(loadindex);
                }
            }
        });
        //显示菜单
        function TableMenu() {
            return layui.myTable.render({
                ismenu: true, elem: '#table_1', id: 'table_1', url: 'SysMenuListDataApi'
                , toolbar: '#bar_title_grade3', title: '系统菜单表'
                , where: {pmenu_id: pmenu_id, grade: grade}
                , cols: [[
                    {type: 'checkbox', width: 36, fixed: 'left'}
                    , {field: 'menu_grade', title: '菜单等级', width: 70, align: 'center'}
                    , {field: 'menu_id', title: '菜单ID', width: 60, align: 'center'}
                    , {field: 'sindex', title: '顺序', width: 60, align: 'center', edit: 'text'}
                    , {field: 'menu_icon', title: '图标', width: 80, align: 'center', templet: '<div><li class="layui-icon {{ d.menu_icon }}"></li></div>', hide: true}
                    , {field: 'menu_name', title: '菜单名称', width: 120}
                    , {field: 'menu_path', title: '路经', width: 150}
                    , {field: 'menu_role_name', width: 200, title: '权限(角色)'}
                    , {field: 'menu_user_name', width: 120, title: '权限(人员)'}
                    , {field: 'menu_desc', title: '备注'}
                ]]
                , page: true, limit: 10
                , editField: {url: 'ModifySysMenuFieldApi', key: 'menu_id'}
            });
        }

        //显示功能
        function TableActivity() {
            return layui.myTable.render({
                ismenu: false, elem: '#table_1', id: 'table_1', url: 'SysMenuActivityListDataApi', skin: 'line'
                , toolbar: '#bar_title_grade3', title: '菜单表'
                , where: {menu_id: pmenu_id, grade: 3}
                , cols: [[
                    {type: 'checkbox', width: 36, fixed: 'left'}
                    , {field: 'act_id', title: '功能ID', width: 80, align: 'center', sort: true}
                    , {field: 'act_name', title: '功能名称', width: 150}
                    , {field: 'act_path', title: '功能路经', width: 300}
                    , {field: 'html_role', title: '角色（权限）', width: 150}
                    , {field: 'html_user', title: '人员（权限）', width: 120}
                    , {field: 'act_desc', title: '备注'}
                    , {field: 'is_log', title: '记录日志', width: 80, align: 'center', templet: '#temp_is_log'}
                ]]
                , page: true, limit: 10
                , editField: {url: 'ModifySysMenuFieldApi', key: 'menu_id'}
            });
        }

        //默认表格列表显示菜单
        tableindex = TableMenu();

        layui.util.event("lay-event", {
            LoadRootMenu: function () {
                top.layer.load();
                pmenu_id = 0, grade = 0;
                tableindex = TableMenu();
                table.hideCol("table_1", [{field: 'menu_icon', hide: false}]);
                $("#titles").html("根菜单 / <span class=\"menudesc\">一级菜单</span>");
                tableindex.reload({toolbar: '#bar_title_grade1', where: {pmenu_id: 0, grade: 0}});
                top.layer.closeAll();
            }
            , SysMenuPathList: function () {
                index = top.layer.open({
                    type: 2, maxmin: true, offset: '60px', area: ['1000px', '550px'], title: ['访问路经', 'font-size:15px;'],
                    content: ["sysmenu/SysMenuPathList", 'yes'],
                    end: function () {
                        tableindex.reload({});
                    }
                });
            }
            , LoadTree: function () {
                treeindex.reload();
            }
            , DoSearch: function () {
                var loadindex = layer.load(1);
                if (grade == 3) {
                    tableindex.reload({where: {menu_id: pmenu_id, menu_path: $("#menupath").val()}});
                } else {
                    tableindex.reload({where: {pmenu_id: pmenu_id, grade: grade, menupath: $("#menupath").val()}});
                }
                layer.close(loadindex);
            }
        });

        //头工具栏事件
        table.on('toolbar(table_1)', function (obj) {
            myTool.toolbar(this, obj, {
                AddSysMenuFirst: function () {
                    index = top.layer.open({
                        type: 2, maxmin: true, offset: '60px', area: ['750px', '550px'], title: false,
                        content: ["sysmenu/AddSysMenuFirst?pmenu_id=0&grade=1", 'no'],
                        end: function () {
                            tableindex.reload({});
                        }
                    });
                }
                , EditSysMenuFirst: function () {
                    layui.myTool.doSingleSelect(table.checkStatus('table_1'), {}, function (data) {
                        index = top.layer.open({
                            type: 2, maxmin: true, offset: '60px', area: ['750px', '550px'], title: false,
                            content: ["sysmenu/EditSysMenuFirst?menu_id=" + data[0].menu_id, 'no']
                            , end: function () {
                                tableindex.reload();
                            }
                        });
                    });
                }
                , AddSysMenuSecond: function () {
                    index = top.layer.open({
                        type: 2, maxmin: true, offset: '60px', area: ['750px', '550px'], title: false,
                        content: ["sysmenu/AddSysMenuSecond?pmenu_id=" + $("#pmenu_id").val() + "&grade=2", 'no'],
                        end: function () {
                            tableindex.reload({});
                        }
                    });
                }
                , EditSysMenuSecond: function () {
                    layui.myTool.doSingleSelect(table.checkStatus('table_1'), {}, function (data) {
                        index = top.layer.open({
                            type: 2, maxmin: true, offset: '60px', area: ['750px', '550px'], title: false,
                            content: ["sysmenu/EditSysMenuSecond?menu_id=" + data[0].menu_id, 'no']
                            , end: function () {
                                tableindex.reload();
                            }
                        });
                    });
                }
                , AddSysMenuThird: function () {
                    index = top.layer.open({
                        type: 2, maxmin: true, offset: '60px', area: ['750px', '550px'], title: false,
                        content: ["sysmenu/AddSysMenuThird?pmenu_id=" + $("#pmenu_id").val(), 'no'],
                        end: function () {
                            tableindex.reload({});
                        }
                    });
                }
                , EditSysMenuThird: function () {
                    layui.myTool.doSingleSelect(table.checkStatus('table_1'), {}, function (data) {
                        index = top.layer.open({
                            type: 2, maxmin: true, offset: '60px', area: ['750px', '550px'], title: false,
                            content: ["sysmenu/EditSysMenuThird?menu_id=" + data[0].menu_id, 'no']
                            , end: function () {
                                tableindex.reload();
                            }
                        });
                    });
                }
                , DelSysMenu: function () {
                    myTool.doSingleSelect(table.checkStatus('table_1'), {key: 'menu_id'}, function (data, keys) {
                        index = top.layer.confirm('你是否确认删除【' + data[0].menu_name + '】', {icon: 3, title: '提示', offset: '30vh'}, function (index2) {
                            myTool.postMsg("DelSysMenuApi", {menu_id: data[0].menu_id}, function () {
                                top.layer.close(index2);
                                tableindex.reload();
                            });
                        });
                    });
                }
                , SetMenuRole: function () {
                    myTool.doSingleSelect(layui.myTable.checkStatus('table_1'), {}, function (data, keys) {
                        index = top.layer.open({
                            type: 2, offset: '60px', area: ['750px', '550px'], title: false,
                            content: ["sysmenu/SetMenuRole?menu_id=" + data[0].menu_id, 'no'],
                            end: function () {
                                tableindex.reload({});
                            }
                        });
                    });
                }
                , SetMenuUser: function () {
                    myTool.doSingleSelect(layui.myTable.checkStatus('table_1'), {}, function (data, keys) {
                        index = top.layer.open({
                            type: 2, offset: '60px', area: ['750px', '550px'], title: false,
                            content: ["sysmenu/SetMenuUser?menu_id=" + data[0].menu_id, 'no'],
                            end: function () {
                                tableindex.reload({});
                            }
                        });
                    });
                }
                , DrSysActivityList: function () {
                    index = top.layer.open({
                        type: 2, maxmin: true, offset: '60px', area: ['990px', '590px'],
                        title: ['导入功能至菜单', 'font-size:15px;'],
                        content: ["sysmenu/DrSysActivityList?menu_id=" + pmenu_id, 'no']
                        , end: function () {
                            tableindex.reload();
                        }
                    });
                }
                , SetActivityRole: function () {
                    myTool.doSingleSelect(layui.myTable.checkStatus('table_1'), {}, function (data, keys) {
                        index = top.layer.open({
                            type: 2, offset: '60px', area: ['750px', '550px'], title: false,
                            content: ["sysactivity/SetActivityRole?act_id=" + data[0].act_id, 'no'],
                            end: function () {
                                tableindex.reload({});
                            }
                        });
                    });
                }
                , SetActivityUser: function () {
                    myTool.doSingleSelect(layui.myTable.checkStatus('table_1'), {}, function (data, keys) {
                        index = top.layer.open({
                            type: 2, offset: '60px', area: ['750px', '550px'], title: false,
                            content: ["sysactivity/SetActivityUser?act_id=" + data[0].act_id, 'no'],
                            end: function () {
                                tableindex.reload({});
                            }
                        });
                    });
                }
                , EditSysActivity: function () {
                    myTool.doSingleSelect(layui.myTable.checkStatus('table_1'), {}, function (data, keys) {
                        index = top.layer.open({
                            type: 2, offset: '60px', area: ['750px', '550px'], title: false,
                            content: ["sysactivity/EditSysActivity?act_id=" + data[0].act_id, 'no'],
                            end: function () {
                                tableindex.reload({});
                            }
                        });
                    });
                }
                , DelSysMenuActivity: function () {
                    myTool.doSingleSelect(layui.myTable.checkStatus('table_1'), {}, function (data, keys) {
                        index = top.layer.confirm('你是否确认删除功能功能【' + data[0].act_id + '】', {icon: 3, title: '提示', offset: '150px'}, function (index2) {
                            myTool.postMsg("DelSysMenuActivityApi", {
                                act_id: data[0].act_id, menu_id: $("#pmenu_id").val()
                            }, function () {
                                top.layer.close(index2);
                                tableindex.reload();
                            });
                        });
                    });
                }
                , ScyActivityPath: function () {
                    myTool.doSingleSelect(layui.myTable.checkStatus('table_1'), {}, function (data, keys) {
                        index = top.layer.confirm('你是否确认同步功能链接至菜单【' + data[0].act_id + '】', {icon: 3, title: '提示', offset: '150px'}, function (index2) {
                            myTool.postMsg("ScyActivityPathApi", {
                                act_id: data[0].act_id, menu_id: $("#pmenu_id").val()
                            }, function () {
                                top.layer.close(index2);
                                tableindex.reload();
                            });
                        });
                    });
                }

            });
        });
        //双击事件
        table.on('rowDouble(table_1)', function (obj) {
            if (obj.config.ismenu) {
                if (grade == 0) {
                    top.layer.open({
                        type: 2, maxmin: true, offset: '60px', area: ['750px', '550px'],
                        title: false,
                        content: ["sysmenu/EditSysMenuFirst?menu_id=" + obj.data.menu_id, 'no']
                        , end: function () {
                            tableindex.reload();
                        }
                    });
                } else if (grade == 1) {
                    top.layer.open({
                        type: 2, maxmin: true, offset: '60px', area: ['750px', '550px'],
                        title: false,
                        content: ["sysmenu/EditSysMenuSecond?menu_id=" + obj.data.menu_id, 'no']
                        , end: function () {
                            tableindex.reload();
                        }
                    });
                } else if (grade == 2) {
                    top.layer.open({
                        type: 2, maxmin: true, offset: '60px', area: ['750px', '550px'], title: false,
                        content: ["sysmenu/EditSysMenuThird?menu_id=" + obj.data.menu_id, 'no']
                        , end: function () {
                            tableindex.reload();
                        }
                    });
                }
            } else {
                top.layer.open({
                    type: 2, offset: '60px', area: ['750px', '550px'], title: false,
                    content: ["sysactivity/EditSysActivity?act_id=" + obj.data.act_id, 'no'],
                    end: function () {
                        tableindex.reload({});
                    }
                });
            }
        });

        form.on('checkbox(ChangeActivityTag)', function (obj) {
            myTool.postMsg("ChangeSysActivityColumnApi", {key: this.value, field: $(obj.elem).attr("field"), msg: $(obj.elem).attr("msg")}, function (result) {
                layer.tips(result.msg, obj.othis);
            });
        });

    });
</script>
#include("../../comm/Foot.html")